package com.yegs.jindie.service;

import com.alibaba.fastjson.JSONObject;
import com.yegs.jindie.service.BaseService;
import org.springframework.stereotype.Service;

@Service
public class AuthService extends BaseService {

    private static final String URL = "https://api.kingdee.com/auth/user/access_token";

    public String getAccessToken() {
        String body = super.get(this.getUrl());
        JSONObject responseBody = JSONObject.parseObject(body);
        if(responseBody.getInteger("errcode") == 0){
            JSONObject data = responseBody.getJSONObject("data");
            String access_token = data.getString("access_token");
            return access_token;
        }
        return null;
    }

    protected String getUrl() {
        String url_request = URL+"?client_id="+basisTO.getClientid()+
                "&client_secret="+basisTO.getClientsecret()+
                "&username="+basisTO.getAuthUsername()+
                "&password="+basisTO.getAuthPassowrd();
        return url_request;
    }
}
